package com.itheima.mall.controller;


import com.itheima.mall.mapper.SkuStockMapper;
import com.itheima.mall.pojo.SkuStock;
import com.itheima.mall.service.PmsSkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {

    @Autowired
    private PmsSkuStockService pmsSkuStockService;
    //批量更新sku库存信息
    @PostMapping("/update/{pid}")
    public ResponseEntity updateSkuStocksByPid(@PathVariable("pid") Integer pid , List<SkuStock> skuStockList){

        pmsSkuStockService.updateSkuStocksByPid(pid , skuStockList);
        return  ResponseEntity.ok("");
    }
    //根据商品ID及sku编码模糊搜索sku库存
    @GetMapping("/{pid}")
    public ResponseEntity selectSkuStockById(@PathVariable("pid") Integer pid ,String keyword){
       List<SkuStock> list = pmsSkuStockService.selectSkuStockById(pid , keyword);
        return ResponseEntity.ok(list);
    }

}
